let api = require('../../Datas/api.js');
var app = getApp();

Page({
  /** 
   * 页面的初始数据 
   */
  data: {
    currentNavtab: 0,//当前第几个swiper 
    recommendList: [],
    bannerlist: [
      // 'https://m.360buyimg.com/mobilecms/s1125x549_jfs/t14671/116/1034460786/180498/4ea33524/5a42131fN633da07e.jpg!q70.jpg',
      // 'https://img1.360buyimg.com/da/jfs/t15142/41/986414713/100026/c132e1d3/5a41bb0dNebed77c7.jpg',
      // 'https://img1.360buyimg.com/da/jfs/t15205/25/1046384225/336158/6436686a/5a4314faN35501535.jpg'
    ],//图片切换数组  
    indicatorDots: true,
    autoplay: true,
    interval: 5000,
    duration: 500,
    scrollWidth: 0,
    imgheights: []
  },

  /** 
   * 生命周期函数--监听页面加载 
   */
  onLoad: function (options) {
    var that = this;
    wx.getSystemInfo({
      success: function (res) {
        //获取屏幕的宽度并保存  
        that.setData({
          scrollWidth: res.windowWidth
        });
      }
    });

    this.getBannerList();
    this.getRecommendList();
  },

  //获取banner列表
  getBannerList: function (e) {
    let param = {
      API_URL: app.globalData.apiUrl + 'videoData/getBanners ',
    
      data: {
      }
    };

    api.result(param).then(data => {
      console.log(data)
      let datas = data.data.data;
      console.log(datas)
       this.setData({
         bannerlist: datas,
       })

    }).catch(e => {
      console.log(e)
      // this.setData({
      //   loadtxt: '数据加载异常',
      //   loading: false
      // })

    })
  },

  //获取推荐列表
  getRecommendList: function (e) {
    let param = {
      API_URL: app.globalData.apiUrl + 'videoData/getNewVideo',
      data: {
      }
    };

    api.result(param).then(data => {
      console.log(data)
      let datas = data.data.data;
      console.log(datas)
      this.setData({
        recommendList: datas,
      })

    }).catch(e => {
      console.log(e)
      // this.setData({
      //   loadtxt: '数据加载异常',
      //   loading: false
      // })

    })
  },

  /*** 预览图片****/
  previewImage: function (e) {
    var current = e.currentTarget.dataset.src;
    wx.previewImage({
      current: current,// 当前显示图片的http链接   
      urls: this.data.bannerlist // 需要预览的图片http链接列表    
    })
  },
  //等比缩放图片并保存  
  imageLoad: function (e) {
    //获取图片真实宽度    
    var imgwidth = e.detail.width,
      imgheight = e.detail.height,
      //宽高比    
      ratio = imgwidth / imgheight;
    //console.log(imgwidth, imgheight);  
    //计算的高度值    

    var viewHeight = parseInt(this.data.scrollWidth) / ratio;
    var imgheight = viewHeight.toFixed(0);
    var imgheightarray = this.data.imgheights;
    //把每一张图片的高度记录到数组里  
    imgheightarray.push(imgheight);

    this.setData({
      imgheights: imgheightarray,
    });
  },
  swiperChange: function (e) {
    //console.log(e.detail.current);      
    this.setData({
      currentNavtab: e.detail.current
    })
  }
})  